package com.data.modules.quartz.job;

import cn.hutool.core.collection.CollUtil;
import com.data.common.entity.TaskQiYeWeiXinMsg;
import com.data.modules.feign.TaskService;
import com.data.modules.log.service.IWsLogService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Date 2022/3/8 17:19
 * @Author funing
 */
@Component
@Slf4j
public class IWsLogJob implements Job {

    @Autowired
    private IWsLogService wsLogService;
    @Autowired
    @Lazy
    private TaskService taskService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<String> deviceIdList = wsLogService.findData();
        List<String> list = new ArrayList();
        if(CollUtil.isNotEmpty(deviceIdList)){
            deviceIdList.forEach(obj->{
                if(wsLogService.heartbeatDetection(obj) == 0){
                    list.add(obj);
                }
            });
        }
        if(CollUtil.isNotEmpty(list)){
            list.forEach(obj->{
                TaskQiYeWeiXinMsg taskQiYeWeiXinMsg = new TaskQiYeWeiXinMsg();
                taskQiYeWeiXinMsg.setFeedbackCategoryCode(4000);
                taskQiYeWeiXinMsg.setTypeId(obj);
                taskQiYeWeiXinMsg.setMinutes(5);
                taskService.companyWeiXinSend(taskQiYeWeiXinMsg);
            });
        }
    }
}
